﻿//Copyright (c) Chris Pietschmann 2013 (http://pietschsoft.com)
//Licensed under the GNU Library General Public License (LGPL)
//License can be found here: http://easypatterns.codeplex.com/license

using EasyPatterns.Factory;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace EasyPatterns.Test.Factory
{
    [TestClass]
    public class FactoryTest
    {
        [TestMethod]
        public void CreateFactory_Lambda_001()
        {
            var factory = EasyPatterns.Factory.Factory.CreateFactory(() =>
            {
                return new DataAccessLayer();
            });

            var actual = factory.Create();

            Assert.IsNotNull(factory);
            Assert.IsInstanceOfType(factory, typeof(LambdaFactory<DataAccessLayer>));
        }

        [TestMethod]
        public void CreateFactory_Lambda_002()
        {
            var factory = EasyPatterns.Factory.Factory.CreateFactory(() =>
            {
                return new DataAccessLayer() as IDataAccessLayer;
            });

            var actual = factory.Create();

            Assert.IsNotNull(factory);
            Assert.IsInstanceOfType(factory, typeof(LambdaFactory<IDataAccessLayer>));
        }

        [TestMethod]
        public void CreateFactory_Lambda_003()
        {
            var factory = EasyPatterns.Factory.Factory.CreateFactory<IDataAccessLayer>(() =>
            {
                return new DataAccessLayer();
            });

            var actual = factory.Create();

            Assert.IsNotNull(factory);
            Assert.IsInstanceOfType(factory, typeof(LambdaFactory<IDataAccessLayer>));
        }

        [TestMethod]
        public void CreateFactory_Simple_001()
        {
            var factory = EasyPatterns.Factory.Factory.CreateFactory<DataAccessLayer>();

            Assert.IsNotNull(factory);
            Assert.IsInstanceOfType(factory, typeof(SimpleFactory<DataAccessLayer>));
        }

        [TestMethod]
        public void CreateFactory_LambdaParameter_001()
        {
            var factory = EasyPatterns.Factory.Factory.CreateFactory<DataAccessLayer>("test");

            Assert.IsNotNull(factory);
            Assert.IsInstanceOfType(factory, typeof(LambdaFactory<DataAccessLayer>));

            var actual = factory.Create();
            Assert.AreEqual("test", actual.GetData());
        }
    }
}
